<template>
  <div>
    <img v-if="flag" class="top-pic" src="@/assets/bg.png" alt="" />
    <img v-else class="top-pic" src="@/assets/avatar1.png" alt="" />
    <div class="card">
      <div class="pic"><img src="@/assets/avatar.png" alt="" /></div>
      <div class="text">{{ title }}</div>
      <van-button
        v-if="flag"
        type="primary"
        size="small"
        class="btn"
        @click="$router.push('/login')"
        >去登录</van-button
      >
      <van-button v-else type="primary" size="small" class="btn" @click="tui"
        >退出</van-button
      >
      <p v-if="!flag">编辑个人资料 ▶</p>
    </div>
    <van-grid :column-num="3" :border="false">
      <van-grid-item icon="star-o" text="我的收藏" />
      <van-grid-item icon="wap-home-o" text="我的出租" />
      <van-grid-item icon="underway-o" text="看房记录" />
      <van-grid-item icon="vip-card-o" text="成为房主" />
      <van-grid-item icon="user-o" text="个人资料" />
      <van-grid-item icon="service-o" text="联系我们" />
    </van-grid>
    <img src="@/assets/join.png" alt="" class="bottom-pic" />
  </div>
</template>

<script>
import { getToken, removeToken } from '@/utils/storage'
export default {
  name: 'MyMy',
  components: {},
  props: {},
  data() {
    return {
      flag: true,
      title: '游客'
    }
  },
  computed: {},
  watch: {},
  created() {
    if (getToken()) {
      this.flag = false
      this.title = '好客_12138'
    } else {
      this.flag = true
    }
  },
  methods: {
    tui() {
      removeToken()
      this.$router.push('/login')
    }
  }
}
</script>

<style scoped lang="less">
p {
  font-size: 12px;
  margin-top: 8px;
}
.bottom-pic {
  width: 92vw;
  margin-left: 15px;
  margin-top: 20px;
}
.van-grid {
  margin-top: -50px;
}
.top-pic {
  width: 100vw;
}
.card {
  height: 160px;
  box-shadow: 0 1px 3px #bdbdbd;
  // position: absolute;
  transform: translateY(-40%);
  margin-left: 30px;
  width: 320px;
  background-color: white;
  text-align: center;
  .text {
    margin-top: -10px;
  }
  .pic {
    transform: translateY(-50%);
    margin-left: 125px;
    box-shadow: 0 1px 3px #bdbdbd;
    width: 70px;
    height: 70px;
    border: 5px solid #f5f5f5;
    border-radius: 50%;
    img {
      width: 100%;
    }
  }
}
::v-deep.van-button--primary {
  margin-top: 20px;
  width: 70px;
  height: 30px;
  background-color: #21b97a;
  border-radius: 5px;
}
</style>
